//数据组件
//用户
<template>
    <div>
    <el-table :data="tableData"
    :header-cell-style="{background:'#3DC5A1',color:'#555'}"
    :border="true">
      <el-table-column prop="messageboardId" label="问答号" width="300">
      </el-table-column>
      <el-table-column prop="issueCreator" label="发布者" width="300">
      </el-table-column>
      <el-table-column prop="answerText" label="简介" width="300">
      </el-table-column>
      <el-table-column prop="operate" label="操作" width="300">
      <template #default="scope">
        <el-popconfirm
          title="确定删除吗？"
          @confirm="del(scope.row.messageboardId)"
          style="margin-left:5px">
          <el-button slot="reference" size="small" table="delete" >删除</el-button>
          </el-popconfirm>
      </template>
                 
      </el-table-column>
      </el-table>
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[7, 10, 12]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    
    </div>
</template>

<script>
export default {
  name: "USer",
  mounted() {
    this.loadPost(); // 确保在组件挂载后加载数据
},
  data() {
      return {
        tableData:[],
        pageNum:1,
        pageSize:7,
        total:1,
        messageboardId:"",
      }
    },
    methods: {
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageNum=1;
        this.pageSize=val;
        this.loadPost();
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.pageNum=val;
        this.loadPost();
      },
      loadGet(){
          this.$axios.get('http://localhost:8082/messageboard-info/list').then(res=>res.data).then(res=>{
              console.log(res);
              this.tableData = res;
          })
      },
      loadPost(){
            this.$axios.post('http://localhost:8082/messageboard-info/listPage',{
              pageNum:this.pageNum,
              pageSize:this.pageSize,
              total:this.total,
              
            }).then(res=>res.data).then(res=>{
                console.log(res)
                if (res.code==200){
                    this.tableData = res.data;
                    this.total=res.total;
                    
                }else{
                    alert("获取失败")
                }
            })
        },
        del(MessageboardId){
          console.log(MessageboardId)
            this.$axios.get('http://localhost:8082/message-board/delete?issueId='+MessageboardId).then(res=>res.data).then(res=>{
                console.log(res)
                if (res.code==200){
                  this.$message({
                  message: '删除成功'
                });
                  this.loadPost()
                }else{
                  this.$message({
                  message: '删除失败'
                });
                }
            })
          },
    beforeMount() {
        this.loadGet();
    },
  }
}
</script>